﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for CountryBusiness
/// </summary>
public class CountryBusiness
{
	public CountryBusiness()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public bool Insert(CountryEntities item)
    {
        bool flat = false;
        SqlParameter image = new SqlParameter("@countryImage", SqlDbType.Image);

        string[] para = { "@countrySymbol", "@countryName", "@countryImage", "@countrySummary", "@countryInfo", "@panelID" };
        string[] values = { item._countrySymbol, item._countryName,"",item._countrySummary, item._countryInfo ,item._panelID.ToString()};
        if (DataAccess.ImageProcedure("sp_InsertCountry",para,values,"@countryImage",item._countryImage) > 0)
        {
            flat = true;
        }
        else
            flat = false;
        return flat;
    }

    public bool Edit(CountryEntities item,bool isImage)
    {
        bool flat = false;
        string tmp = "0";
        if (isImage)
            tmp = "1";
        string[] para = { "@countryID", "@countrySymbol", "@countryName", "@countryImage", "@countrySummary", "@countryInfo", "@isImage" };
        string[] values = { item._countryID.ToString(), item._countrySymbol, item._countryName, "",item._countrySummary, item._countryInfo, tmp };
        if (DataAccess.ImageProcedure("sp_UpdateCountry",para,values,"@countryImage",item._countryImage) > 0)
            flat = true;
        else
            flat = false;
        return flat;
    }

    public bool Delete(int id)
    {
        if (DataAccess.getExec("exec sp_DeleteCountry '"+id+"'") > 0)
            return true;
        else
            return false;
    }

    public DataTable getAllCountry()
    {
        return DataAccess.DataTable_Query("exec sp_GetCountry ''");
    }

    

    public DataTable getRandomCountry()
    {
        return DataAccess.DataTable_Query("exec sp_GetRandomCountry");
    }

    public DataTable getCountryTable(int countryID)
    {
        return DataAccess.DataTable_Query("exec sp_GetCountry '" + countryID + "'");
    }

    public CountryEntities getCountry(int id)
    {
        CountryEntities ce = new CountryEntities();
        DataTable dt = DataAccess.DataTable_Query("exec sp_GetCountry '"+id+"'");
        if (dt != null)
        {
            DataRow dr=dt.Rows[0];
            ce._countryID = int.Parse(dr["countryID"].ToString());
            ce._countrySymbol = dr["countrySymbol"].ToString();
            ce._countryName = dr["countryName"].ToString();
            ce._countrySummary = dr["countrySummary"].ToString();
            ce._countryInfo = dr["countryInfo"].ToString();
        }
        return ce;
    }
    public DataTable getCountryBy(string[] TableName, string[] fields, string Criterias, string priorities)
    {
        DataTable dt = new DataTable();
        string query = SQLQuery.SQLQuery_SELECT(TableName, fields, Criterias, priorities);
        return dt = DataAccess.DataTable_Query(query);
    }
}